﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfSnqkGasAnalysis.IBusiness_impl;

namespace WpfSnqkGasAnalysis
{
    /// <summary>
    /// Login.xaml 的交互逻辑
    /// </summary>
    public partial class Login : Window
    {
        public Login()
        {
            InitializeComponent();
        }
 
        //登录
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            UserBusiness userBusiness = new UserBusiness();
            var result = userBusiness.CheckLogin(this.account.Text, this.password.Password);
            if (result.Code != 200)
            {
                //MessageBox.Show(result.Msg, "登录验证", MessageBoxButton.OK, MessageBoxImage.Error);
                ShowAlertHelpter.ShowAlert(result.Msg);
                e.Handled = true;
                return;
            }
           
            MainWindow.Instance.Show();

            this.Close();
        }
         
        /// 登录回车处理。创建时间：2022-11-24 16:09:26
        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            //回车事件
            if (e.Key == Key.Enter)
            {
                btnLogin.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                //MessageBox.Show("提交登录");
            }
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            if (MainWindow.Instance.Visibility== Visibility.Hidden)
            {
                MainWindow.Instance.Close();
            }

            this.Close();
        }
    }
}
